﻿using System.Collections.Generic;
using ECG.Common;

namespace ECG.DAL
{
    public partial class ProductImageDb
    {
        /// <summary>
        /// Get product image has color infomation
        /// </summary>
        /// <param name="productId"></param>
        /// <returns></returns>
        public static List<ProductImageHasColorNameDto> GetImagesByProductId(string productId)
        {
            var dao = SharedSqlDao;
            var command = dao.GetDbSprocCommand("WSPX_ProductImage_GetAllByProductIdHasColorName");
            try
            {
                command.Parameters.Add(dao.CreateParameter("@ProductId", productId));
                var result = dao.GetDTOList<ProductImageHasColorNameDto>(ref command);
                return result;
            }
            finally
            {
                command.Connection.Close();
            }
        }

        /// <summary>
        /// Get image and color information
        /// </summary>
        /// <param name="productId"></param>
        /// <returns></returns>
        public static List<ProductImageHasColorInfoDto> GetImageHasColorInfo(string productId)
        {
            var dao = SharedSqlDao;
            var command = dao.GetDbSprocCommand("WSPX_ProductImage_GetAllByProductIdHasColorInfo");
            try
            {
                command.Parameters.Add(dao.CreateParameter("@ProductId", productId));
                var result = dao.GetDTOList<ProductImageHasColorInfoDto>(ref command);
                return result;
            }
            finally
            {
                command.Connection.Close();
            }
        }

        public static List<ProductImageHasColorInfoDto> GetImageByColorId(string productId, string ColorId)
        {
            var dao = SharedSqlDao;
            var command = dao.GetDbSprocCommand("WSPX_ProductImage_GetByColorIdOnProductDetail");
            try
            {
                command.Parameters.Add(dao.CreateParameter("@ProductId", productId));
                command.Parameters.Add(dao.CreateParameter("@ColorId", ColorId));
                var result = dao.GetDTOList<ProductImageHasColorInfoDto>(ref command);
                return result;
            }
            finally
            {
                command.Connection.Close();
            }
        }
        /// <summary>
        /// Get images by id and has color information
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static ProductImageHasColorNameDto GetImagesById(string id)
        {
            var dao = SharedSqlDao;
            var command = dao.GetDbSprocCommand("WSPX_ProductImage_GetAllImagesHasColorInfo");
            try
            {
                command.Parameters.Add(dao.CreateParameter("@Id", id));
                var result = dao.GetSingleDTO<ProductImageHasColorNameDto>(ref command);
                return result;
            }
            finally
            {
                command.Connection.Close();
            }
        }

    }
}
